package com.project.customview.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

import com.project.customview.R;

public class CustomView extends View {
    Paint paint;
    Context mContext;
    //字体颜色
    int tColor;
    //字体大小
    int tTextSize;
    boolean fBoolean;
    float floatf;
    String tText;
    public CustomView(Context context) {
        super(context);

        mContext = context;
    }

    public CustomView(Context context,@Nullable AttributeSet attrs) {
        super(context, attrs);

        TypedArray typedArray = context.obtainStyledAttributes(attrs,R.styleable.CustomView);
        tColor = typedArray.getColor(R.styleable.CustomView_tColor,Color.BLUE);
        fBoolean = typedArray.getBoolean(R.styleable.CustomView_fBoolean,false);
        floatf = typedArray.getFloat(R.styleable.CustomView_fromFloat,1f);
        tText = typedArray.getString(R.styleable.CustomView_tText);
        tTextSize = typedArray.getDimensionPixelOffset(R.styleable.CustomView_tTextSize,25);
        typedArray.recycle();
        Log.i("aaa","tcolor的值是"+tColor);
        Log.i("aaa","fBoolean的值是"+fBoolean);
        Log.i("aaa","floatf的值是"+floatf);
        Log.i("aaa","tText的值是"+tText);
        Log.i("aaa","tTextSize的值是"+tTextSize);
        paint = new Paint();
        paint.setColor(tColor);
        paint.setTextSize(tTextSize);


    }

    public CustomView(Context context,  @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawText(tText, getWidth()/2, getHeight()/2, paint);

    }
}
